<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close" :append-to-body="true" :modal-append-to-body="true">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="12">
          <el-form-item label="任命类型" prop="appointmenttype" :rules="rules.validateRequire">
            <el-select v-model="model.appointmenttype" :disabled="true">
              <el-option v-for="item in codeModel.appointmenttypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="排序码" prop="sortcode">
            <el-input-number v-model="model.sortcode" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="姓名" prop="usercode" :rules="rules.validateRequire">
            <!-- <el-input v-model="model.username"></el-input> -->
            <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.username" dataType="code" :singleSelect="true" :disabled="candelete">
            </tl-ref-user>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工号" prop="usercode" :rules="rules.validateRequire">
            <el-input v-model="model.usercode" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="工作组名称" prop="workgroup">
            <el-input :disabled="true" v-model="model.workgroup"></el-input>
            <!-- <el-select v-model="model.workgroup" filterable clearable @change="clear()">
              <el-option v-for="item in codeModel.workgroupList" :key="item.code" :label="item.name"
                :value="item.code" />
            </el-select> -->
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目角色" prop="projectrole" :rules="rules.validateRequire">
            <el-select v-model="model.projectrole" filterable clearable>
              <el-option v-for="item in projectRoleList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="职责" prop="duty" :rules="rules.validateRequire">
            <el-input v-model="model.duty"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '项目任命-项目组成员',
      urlPrefix: '/mpm/projectTeam/',
      url: {
        // 额外的url
        queryCodeList: '/mpm/projectTeam/dataCodeList'
      },
      projectRoleList: []
    }
  },
  props: {
    parentId: {
      type: [Number, String],
      default: ''
    },
    teamType: {
      type: [Number],
      default: 0
    },
    teamName: {
      type: String,
      default: ''
    },
    candelete: {
      type: Number,
      default: 0
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
      if (this.isAdd) {
        this.$set(this.model, 'projectcode', this.parentId)
        this.$set(this.model, 'teamid', this.teamType)
        this.$set(this.model, 'workgroup', this.teamName)
      }
    },
    /** 查询编码 */
    doQueryCode() {
      if (this.url.queryCodeList) {
        getAction(this.url.queryCodeList, {}).then((res) => {
          if (res.success) {
            this.codeModel = res.result
            if (this.codeModel.projectroleList && this.codeModel.projectroleList.length > 0) {
              this.projectRoleList = this.codeModel.projectroleList.filter(item => (item.code === 'gruopworker' || item.code === 'groupleader'))
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      }
    }
  }
}
</script>

